package com.crosbymichael.filesystem
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	/**
	 * Reads the sdk's adt nativePath and returns it to be used.
	 *  
	 * @author Michael Crosby crosbymichael.com
	 * 
	 */	
	public class ReadSDKPath
	{
		public function ReadSDKPath()
		{
		}
		
		/**
		 * Reads the file that holds the path to Air's adt file.
		 *  
		 * @return Air's adt's nativePath. 
		 * 
		 */		
		public function readPath():String {
			var f:File = File.applicationStorageDirectory.resolvePath("sdkpath");
			//Check that the files exists
			if (f.exists) {
				var fs:FileStream = new FileStream();
				
				fs.open(f, FileMode.READ);
				var s:String = fs.readUTFBytes(fs.bytesAvailable);
				fs.close();	
				if (sdkFileExist(s)) {
					return s;	
				} else {
					return "";
				}
			} else {
				return "";
			}
		}
		
		private function sdkFileExist(data:String):Boolean {
			var f:File = new File(data);
			if (f.exists) {
				return true;
			} else {
				return false;
			}
		}
	}
}